package com.inspur.ourhis_afterend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Dao.DoctorAdviceDao;
import com.inspur.ourhis_afterend.Dao.PrescribeDao;
import com.inspur.ourhis_afterend.Dao.PrescribeDrugsDao;
import com.inspur.ourhis_afterend.Service.DoctorAdviceService;
import com.inspur.ourhis_afterend.Tools.Result;
import com.inspur.ourhis_afterend.model.DoctorAdvice;
import com.inspur.ourhis_afterend.model.Prescribe;
import com.inspur.ourhis_afterend.model.PrescribeDrugs;
import com.inspur.ourhis_afterend.vo.DoctorAdviceVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.Wrapper;

@RestController
@RequestMapping("/doctorAdvice")
public class DoctorAdviceController {
    @Resource(name ="doctorAdviceService" )
    DoctorAdviceService doctorAdviceService;

    @Resource
    PrescribeDrugsDao prescribeDrugsDao;

    @ApiOperation("按条件动态查询医嘱")
    @ApiParam(value = "传入任意条件")
    @GetMapping("/selectAdSelective")
    public Result selectAdSelect(@RequestParam("pageNo") Integer pageNo,@RequestParam("PageSize") Integer pageSize, @RequestParam(value = "roid",required = false) Integer roid, @RequestParam(value = "memeberid",required = false) Integer memeberid,
                                 @RequestParam(value = "createtime",required = false) String createtime){
        IPage<DoctorAdviceVo> iPage = new Page<>(pageNo,pageSize);
        try {
            return Result.success(doctorAdviceService.selectAdSelect(iPage,roid, memeberid, createtime));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }

    }
    @ApiOperation("更新内容，删除实质是更新状态")
    @ApiParam(value = "daid")
    @PostMapping("/updateAdvice")
    public Result deleteById(@RequestBody DoctorAdvice doctorAdvice){
        try {
            return Result.success(doctorAdviceService.updateByDaid(doctorAdvice));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }

    @ApiOperation("添加药品")
    @ApiParam(value = "详细药品")
    @PostMapping("/addPrescribeDrugs")
    public Result addPrescribeDrugs(@RequestBody  PrescribeDrugs prescribeDrugs){
        try {
            prescribeDrugsDao.insert(prescribeDrugs);
            return Result.success("success");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }

}
